from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from dotenv import load_dotenv
import os
import pymysql

# 使用PyMySQL替代mysqlclient
pymysql.install_as_MySQLdb()

# 加载环境变量
load_dotenv()

# 初始化Flask应用
app = Flask(__name__)

# 配置数据库
app.config["SQLALCHEMY_DATABASE_URI"] = os.getenv("MYSQL_URI")
app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False
app.config["SECRET_KEY"] = os.urandom(24)

# 初始化数据库
db = SQLAlchemy(app)

# 注册路由
from app.routes import main, talent
app.register_blueprint(main.bp)
app.register_blueprint(talent.bp)
